//
//  MiTuGiftApi.swift
//  MT
//
//  Created by M on 2019/12/18.
//  Copyright © 2019 张强. All rights reserved.
//

import Foundation
import Moya
import DeviceKit
import SwiftyRSA
import Security

import Result

enum MiTuGiftApi {
    case list
    case sendGift(_ requestParam: [String : Any])
    /// 收礼物
    case pullGift(_ requestParameters: [String : Any])
    /// 获取聚会任务专享礼物
    case partyGift
}

// MARK: ------------------  ----------------------
extension MiTuGiftApi: MTTargetType {
    
    /// 请求头
    public var headers: [String : String]? {
        guard let accessToken = UserDefaults.MTUserCenter.token.storedString else { return nil }
//        guard let accessToken = UserCenter.default.auth?.token else { return nil }
        return ["Access-Token": accessToken]
    }
    
    /// 基路径
    public var baseURL: URL {
        return URL(string: AuthServerBaseUrl)!
    }
    
    /// 路径
    public var path: String {
        switch self {
        case .list:
            return "/gift/list"
        case .sendGift(_):
            return "/gift/send"
        case .pullGift(_):
            return "/gift/pull"
        case .partyGift:
            return "/gift/party-gift"
        }
    }
    
    /// 请求方法
    public var method: Moya.Method {
        return .post
    }
    
    /// 参数
    var params: [String: Any]? {
        switch self {
        case .list:
            return ["curPage": 1, "pageSize": 100]
        case let .sendGift(requestParam):
            return requestParam
        case let .pullGift(requestParam):
            return requestParam
        case .partyGift:
            return nil
        }
    }
    
}
